package com.dbuil.bleshoes.ui.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;

import androidx.appcompat.widget.AppCompatTextView;

import com.blankj.utilcode.util.LogUtils;


/**
 * Created by Administrator on 2019/2/15.
 * 防止快速点击
 */


public class NofastClickTextview extends AppCompatTextView {

    private long previousTime;

    public NofastClickTextview(Context context) {
        super(context);
    }

    public NofastClickTextview(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

    }

    public NofastClickTextview(Context context, AttributeSet attrs) {
        super(context, attrs);

    }


    /**
     * @param event touch事件
     * @return 是否消耗点击事件
     * true - 消耗点击事件
     * false - 不消耗点击事件
     */
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_UP:
                long currentTime = System.currentTimeMillis();
                if (currentTime - previousTime <1000) {
                    LogUtils.i("快速点击");
                    previousTime = currentTime;
                    return true;
                }
                previousTime = currentTime;
                break;

            default:
                break;
        }
        return super.onTouchEvent(event);
    }

}
